<?php
declare (strict_types = 1);

namespace app\admin\event;

use think\facade\Db;

class WriteLog
{
	public $data;
	public $otherData;
	
    public function __construct()
    {
        $this->otherData['uid'] = session('adminUserInfo.uid');
        $this->otherData['catid'] = session('adminUserInfo.catId');
        $this->otherData['model'] = session('adminUserInfo.model');
    }

    public function writeLogData(){
        if(!$this->data)  return false;

        $this->data = array_merge($this->data, $this->otherData);

        try{
            Db::name('logs')->save($this->data);
        }catch(\Exception $e){
            trace('(saveDataInfo)记录logs失败，logs内容为：' . json_encode($this->data) . '失败原因：' . $e->getMessage(), 'error');
        }
    }

}
